package com.motorhome.manage.service.impl;

import com.motorhome.base.dao.Pager;
import com.motorhome.base.util.FileUtil;
import com.motorhome.base.util.Result;
import com.motorhome.base.util.StringUtil;
import com.motorhome.manage.common.statics.ManageStatics;
import com.motorhome.manage.dao.CarDao;
import com.motorhome.manage.domain.Car;
import com.motorhome.manage.domain.Price;
import com.motorhome.manage.service.CarService;
import com.motorhome.manage.service.CarTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @author: John
 */
@Service
public class CarTypeServiceImpl implements CarTypeService {

    @Autowired
    private CarDao carDao;

    @Override
    public Pager<Car> getCarListType(String page, String rows,String type) {
        Pager<Car> pager = carDao.getCarListType(Integer.parseInt(page), Integer.parseInt(rows),Integer.parseInt(type));
        if (pager.getItems() != null && !pager.getItems().isEmpty()) {
            List<Long> carIds = pager.getItems().stream().map(Car::getId).collect(Collectors.toList());
            List<Price> prices = carDao.getCarPrice(carIds);
            pager.getItems().forEach(car -> car.setPrices(prices.stream().filter(price -> price.getCarId().equals(car.getId())).collect(Collectors.toList())));
        }
        return pager;
    }

//    @Override
//    public Pager<Car> getCarListType(String page, String rows, String type) {
//
//    }
}
